package cn.sms.quartz.job;

import cn.sms.order.service.IAdoptOrderService;
import cn.sms.order.service.IProductOrderService;
import cn.sms.product.service.IProductService;
import cn.sms.quartz.constant.JobConstants;
import cn.sms.quartz.util.QuartzJobInfo;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 统一job
 */
public class MainJob  implements Job{

    @Autowired
    private IAdoptOrderService adoptOrderService;
    @Autowired
    private IProductOrderService productOrderService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext)  {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Map<String,Object> map = (Map<String, Object>) jobDataMap.get("params");

        String type = (String) map.get("type");
        switch (type){
            case JobConstants.TIME_OUT_ADOPT_LAST_PAY:{
                Long orderId = (Long) map.get("orderId");
                adoptOrderService.cancelByQuartz(orderId);
            }
            case JobConstants.TIME_OUT_PRODUCT_LAST_PAY:{
                Long orderId = (Long) map.get("orderId");
                productOrderService.cancelByQuartz(orderId);
            }
        }
    }
}